package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDTO;
import com.zzyl.entity.AlertRule;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/alert-rule")
public class AlertRuleController {

    @Resource
    private AlertRuleService alertRuleService;
    // 创建告警规则
    @PostMapping("/create")
    public ResponseResult createAlertRule(@RequestBody AlertRuleDTO alertRuleDto) {
        return alertRuleService.createAlertRule(alertRuleDto);
    }
    @GetMapping("/get-page")
    public ResponseResult<PageResponse<AlertRuleVo>> getAlertRulePage(@RequestParam("pageNum") Integer pageNum,
                                                                      @RequestParam("pageSize") Integer pageSize,
                                                                      @RequestParam(value = "alertRuleName" ,required = false) String alertRuleName,
                                                                      @RequestParam(value = "productKey" , required = false) String productKey,
                                                                      @RequestParam(value = "functionName", required = false) String functionName) {
        return alertRuleService.getAlertRulePage(pageNum, pageSize, alertRuleName, productKey, functionName);
    }
    @GetMapping("/read/{id}")
    public ResponseResult<AlertRuleVo> getAlertRuleById(@PathVariable Long id) {
        return alertRuleService.getAlertRuleById(id);
    }
    @PutMapping("/update/{id}")
    public ResponseResult updateAlertRule(@RequestBody AlertRuleDTO dto) {
        return alertRuleService.updateAlertRule(dto);
    }
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateAlertRuleStatus(@PathVariable Integer id, @PathVariable Integer status){
        return alertRuleService.updateAlertRuleStatus(id, status);
    }
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteAlertRule(@PathVariable Long id) {
        return alertRuleService.deleteAlertRule(id);
    }


}